class MyStack {
    private int[] arr;
    private int top;
    private int capacity;

    // 构造函数，初始化栈
    public MyStack(int capacity) {
        this.capacity = capacity;
        this.arr = new int[capacity];
        this.top = -1;
    }

    // 入栈操作
    public void push(int value) {
        if (isFull()) {
            System.out.println("栈已满，无法入栈");
            return;
        }
        arr[++top] = value;
    }

    // 出栈操作
    public int pop() {
        if (isEmpty()) {
            System.out.println("栈为空，无法出栈");
            return -1;
        }
        return arr[top--];
    }

    // 获取栈顶元素
    public int peek() {
        if (isEmpty()) {
            System.out.println("栈为空，无栈顶元素");
            return -1;
        }
        return arr[top];
    }

    // 检查栈是否为空
    public boolean isEmpty() {
        return top == -1;
    }

    // 检查栈是否已满
    public boolean isFull() {
        return top == capacity - 1;
    }

    // 获取栈的大小
    public int size() {
        return top + 1;
    }
}

